import 'package:flutter/cupertino.dart';
import 'package:flutter_deer/game/iview/game_list_iview.dart';
import 'package:flutter_deer/game/models/game_item_entity.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:flutter_deer/res/constant.dart';

class GameListPagePresenter extends BasePagePresenter<GameListIMvpView> {

  GameListPagePresenter();

  @override
  void initState() {

  }

  Future<dynamic> getGameList(int? index) async{
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, dynamic> params = <String, dynamic>{};
      params['size'] = Constant.pageSize;
      params['current'] = 1;
      asyncRequestNetwork<BaseEntity<GameItemPageEntity>>(Method.get,
        url: HttpApi.footballGameList.replaceAll('{dateType}', index.toString()),
        queryParameters: params,
        onSuccess: (data) {
          view.setGameItemPage(data!.data);
        },
          onError: (code,msg) {

          }
      );
    });
  }

  Future<dynamic> getMoreGameList(int? index,int? pageNo) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, dynamic> params = <String, dynamic>{};
      params['size'] = Constant.pageSize;
      params['current'] = pageNo;
      asyncRequestNetwork<BaseEntity<GameItemPageEntity>>(Method.get,
        url: HttpApi.footballGameList.replaceAll('{dateType}', index.toString()),
        queryParameters: params,
        onSuccess: (data) {
          view.setGameItemPage(data!.data);
        },
          onError: (code,msg) {

          }
      );
    });
  }

}